﻿using Nutrapp.DBAL;
using Nutrapp.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Nutrapp.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {

            List<Recipe> newestList = new List<Recipe>();
            List<RecipeModel> rm = new List<RecipeModel>();


            using (NutrappDataContext context = new NutrappDataContext())
            {

                newestList = context.Recipes.Take(12).ToList();

                foreach (Recipe recipe in newestList)
                {
                    RecipeModel rec = new RecipeModel(); ;

                    if (recipe != null)
                    {
                        rec.ID = recipe.ID;
                        rec.Name = recipe.Name;
                        rec.Cost = recipe.Cost;
                        rec.Picture = recipe.Picture;
                        rec.Instruction = recipe.Instruction;
                        rec.IngredientLines = recipe.Recipe_Ingredients.ToList();
                        rec.Rating = recipe.Rating;
                        rec.Protein = recipe.Protein.Value;
                        rec.Fat = recipe.Fat.Value;
                        rec.Calories = recipe.Calories.Value;
                        rec.Carbohydrate = recipe.Carbohydrate.Value;
                    }
                    rm.Add(rec);
                }

            }

            var tuple = new Tuple<List<RecipeModel>>(rm);
            return View(tuple);

            
        }

        public ActionResult About()
        {
            ViewBag.Message = "Your app description page.";

            return View();
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }
    }
}
